

#include "matrix.h"
#include "transform.h"

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

vm_vector vects[3]; // Three space orthoganolization.
vm_vector *ortho_vects;
vm_vector normed_ortho_vects[3];
int i;

void generate_vects();
extern vm_matrix *vm_make_space_trans_mtx(vm_vector *);

int main(){

  generate_vects();
  ortho_vects = vm_gram_schmidt_orth(vects, 3);

  printf("Basis vectors:\n");
  for ( i = 0; i < 3; i++){
    vm_println(ortho_vects[i]);
  }
  printf("Normed basis vectors:\n");
  for ( i = 0; i < 3; i++){
    vm_norm(ortho_vects[i], &(normed_ortho_vects[i]));
    vm_println(normed_ortho_vects[i]);
  }

  vm_matrix *trans = vm_make_space_trans_mtx(normed_ortho_vects);
  printf("Space trans matrix:\n");
  vm_print_matrix(trans, " ");

  printf("Transformed basis vectors:\n");
  vm_vector tmp;
  for ( i = 0; i < 3; i++){
    vm_transform(&(normed_ortho_vects[i]), trans, &tmp);
    vm_println(tmp);
  }

  return 0;

}

void generate_vects(){

  for ( i = 0; i < 3; i++){
    srand(time(NULL) + i);
    double x, y, z;//, w;
    x = rand() / (double)100000000;
    y = rand() / (double)100000000;
    z = rand() / (double)100000000;
    //w = rand() / (double)100000000;
    vects[i].x = x;
    vects[i].y = y;
    vects[i].z = z;
    vects[i].w = 0;
  }

}
